package cn.zyjblogs.nio;

import java.nio.ByteBuffer;

/**
 * copyright (C), 2021, 北京同创永益科技发展有限公司
 *
 * @author zhuyijun
 * @version 1.0.0
 * <author>                <time>                  <version>                   <description>
 * zhuyijun         2021/10/8 16:22               1.0
 * @program netty_study
 * @description
 * @create 2021/10/8 16:22
 */
public class NIOByteBufferPutGet {
    public static void main(String[] args) {
        //创建buffer
        ByteBuffer buffer = ByteBuffer.allocate(64);

        //类型化放入数据
        buffer.putInt(100);
        buffer.putLong(9);
        buffer.putChar('逝');
        buffer.putShort((short) 4);
        //取出 翻转缓冲区
        buffer.flip();
        //类型化取出顺序不对可能抛出异常
        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort());
    }
}
